package com.doradance.app;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.doradance.R;
import com.doradance.account.ui.LoginActivity;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.customviews.multiviewpager.MultiViewPager;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GuideActivity extends BaseActivity implements ViewPager.OnPageChangeListener {

    @Bind(R.id.mvpGuide)
    MultiViewPager mvpGuide;
    @Bind(R.id.btnClick)
    View mBtnClick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        hideToolbar();
        mBtnClick.setVisibility(View.GONE);
        //定义全屏参数
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        //获得窗口对象
        Window mywindow = this.getWindow();
        //设置Flag标识
        mywindow.setFlags(flag, flag);

        mvpGuide.setFragmentManager(getSupportFragmentManager());
        initGuideFragment();

//        //设置状态栏黑色
//        if (Build.VERSION.SDK_INT >= 21) {
//            getWindow().setStatusBarColor(Color.BLACK);
//        }
//        mvpGuide.setFragmentManager(getSupportFragmentManager());
//        initGuideFragment();
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.act_guide, null);
    }

    private void initGuideFragment() {
        int[] drawableIDs = new int[]{R.mipmap.guide_111, R.mipmap.guide_222, R.mipmap.guide_333, R.mipmap.guide_444};
        for (int i = 0; i < drawableIDs.length; i++) {

            mvpGuide.add(drawableIDs[i]);
        }
        mvpGuide.setOnPageChangeListener(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        if (position == 3) {
            mBtnClick.setVisibility(View.VISIBLE);
        } else {
            mBtnClick.setVisibility(View.GONE);
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }


    @OnClick({R.id.rl_skip, R.id.btnClick})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_skip:
                LoginActivity.start(this);
                this.finish();
                break;
            case R.id.btnClick:
                LoginActivity.start(this);
                this.finish();
                break;
        }
    }
}
